from time import sleep

from selenium import  webdriver

from selenium.webdriver.common.by import By

from selenium.webdriver.support.wait import WebDriverWait  # 显示等待
from selenium.webdriver.support import  expected_conditions#   #判断条件模块
from selenium.webdriver.support.select import Select    # 下拉框模块

try:
    driver = webdriver.Chrome()
    driver.get("http://192.168.1.138/ranzhi/www/sys/index.html")
    driver.maximize_window()

    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="account"]')))
    driver.find_element(By.XPATH, '//*[@id="account"]').send_keys("")
    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="password"]')))
    driver.find_element(By.XPATH, '//*[@id="password"]').send_keys("123456")
    sleep(2)
    WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="submit"]')))
    driver.find_element(By.XPATH, '//*[@id="submit"]').click()
    sleep(2)
    text = driver.find_element(By.XPATH, "/html/body/div[2]/div/div/div[1]/div").text
    sleep(2)
    assert text == "登录失败，请检查您的成员名或密码是否填写正确。", "输入空的用户名,进行登录,用例执行失败"
    driver.quit()
except Exception as e:
    print(e)




# WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="account"]')))
# driver.find_element(By.XPATH, '//*[@id="account"]').send_keys("admin")
# WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="password"]')))
# driver.find_element(By.XPATH, '//*[@id="password"]').send_keys("")
# WebDriverWait(driver, 10).until(expected_conditions.presence_of_element_located((By.XPATH, '//*[@id="submit"]')))
# driver.find_element(By.XPATH, '//*[@id="submit"]').click()
# sleep(2)
# driver.quit()



